﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using emp.Utility;
using System.Data;
using System.Data.SqlClient;
using emp.SqlServerDAL;
using emp.Model.SysManage;

public partial class crm_memberApprove_MemberApproveBatch : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            System.Data.DataTable dt=getDt();
            this.campaignList.DataSource = dt;
            this.campaignList.DataBind();

            PageUtil.setPageCount(campaignList, dt.Rows.Count);

        }
    }


    private DataTable getTableInfo(string sql)
    {
        DataSet data = new DataSet();
        using (SqlDataAdapter sda = new SqlDataAdapter())
        {
            try
            {
                sda.SelectCommand = new SqlCommand();
                sda.SelectCommand.CommandText = sql;
                sda.SelectCommand.Connection = new SqlConnection(SQLHelper.CONN_STRING_NON_DTC);
                sda.Fill(data);
            }
            catch { }
        }
        return data.Tables[0];
    }





    private DataTable getDt()
    {
        DataTable dt = null;
        string sql = "SELECT  TCB_ID      ,TCB_XLS_FILE      ,TCB_STATUS      ,TCB_VALID_NUM      ,TCB_DOLOAD_USER      ,convert(varchar, TCB_DOLOAD_DATE,111) as TCB_DOLOAD_DATE      ,TCB_REMARK  FROM TASTE_CAR_BATCH  WHERE 1=1";
        if (DATE_BEGN.Text != null && DATE_BEGN.Text!="")
        {
            sql += "   AND TCB_DOLOAD_DATE>='" + DATE_BEGN.Text + " 00:00:00'  ";
        }
        if (DATE_END.Text != null && DATE_END.Text != "")
        {
            sql += "   AND TCB_DOLOAD_DATE<='" + DATE_END.Text + " 23:59:59'  ";
        }


        sql += "  order by TCB_ID desc";

        dt = getTableInfo(sql);
        return dt;
    }







    protected void PageChanged(object sender, GridViewPageEventArgs e)
    {
        gview(e.NewPageIndex);
    }

    private void gview(int page)
    {
        campaignList.PageIndex = PageUtil.getGviewNewPage(campaignList, page);
        this.pageNum.Value = campaignList.PageIndex.ToString();

        DataTable dt = getDt();
        this.campaignList.DataSource = dt;
        this.campaignList.DataBind();

        PageUtil.setPageCount(campaignList, dt.Rows.Count);
    }


    protected void upLoad0_Click1(object sender, EventArgs e)
    {
        Response.Redirect("TasteUpload.aspx", true);
    }
    protected void upLoad_Click(object sender, EventArgs e)
    {
        string[] trem = new string[15];
        
        if (DATE_BEGN.Text != "")
        {
            trem[1] = DATE_BEGN.Text;
        }
        if (DATE_END.Text != "")
        {
            trem[2] = DATE_END.Text;
        }


        System.Data.DataTable dt = getDt();
        this.campaignList.DataSource = dt;
        this.campaignList.DataBind();

        PageUtil.setPageCount(campaignList, dt.Rows.Count);


    }
}
